VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
BEGIN
t := TextModels.dir.New(); (* create a new, empty text *)
f.ConnectTo(t); (* connect a formatter to the text *)
f.WriteString("Hello World"); f.WriteLn; (* write string and 0DX into new text *)
v := TextViews.dir.New(t); (* create a new text view for t *)
Views.OpenView(v) (* open the view in a window *)
END Do;
END ObxHello1.
TextControllers.StdCtrlDesc
TextControllers.ControllerDesc
Containers.ControllerDesc
Controllers.ControllerDesc
Helvetica
DevCommanders.StdViewDesc
DevCommanders.ViewDesc
Helvetica
Oberon by Example: ObxHello1
Everything in Oberon/F revolves around views. A view is a rectangular part of a document; documents consist of a hierarchy of nested views. This text is a text view; below is another text view embedded in it:
ObxHello1.Do
The embedded text view above contains a slightly more advanced hello world program than ObxHello0. It doesn't use module Out to write into the log window; instead it creates a new empty text, to which it connects a text formatter. A text formatter is an object which provides procedures to write variables of all basic Oberon types into a text. In the above example, a string and a carriage return are written to the text, which means that they are appended to the existing text. Since a newly created text is empty, t now contains exactly what the formatter has written into it.
A text is an object which carries text and text attributes; i.e. a sequence of characters and information about font, color, and vertical offset of each character. However, a text does not know how to draw itself; this is the purpose of a text view. (Yes, what you are currently looking at is the output of such a view.) When a text view is created, it receives the text to be displayed as a parameter. Several views on the same text can be open simultaneously. When you edit in one window, the changes are propagated to all other windows on the same text.
When you create a text, you can follow the steps outlined below:
1) create a text model
2) connect a text formatter to it
3) write the text's context via the formatter
4) create a text view for the model
5) open the text view in a window
In this example, we have seen how to use the text subsystem in order to create a new text.